#define  _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
void Swap(char* buf1, char* buf2,int width)
{
	int i = 0;
	for (i = 0; i < width; i++)
	{
		char tmp = *buf1;
		*buf1 = *buf2;
		*buf2 = tmp;
		buf1++;
		buf2++;
	}

}
void bubble_sort(void* base, size_t num, size_t width,
	int (*cmp)(const void* p1, const void* p2))
{
	size_t i;
	for (i = 0; i < num - 1; i++)
	{
		int flag = 1;
		size_t j = 0;
		for (j = 0; j < num - 1 - i; j++)
		{
			if (cmp((char*)base + j * width, (char*)base + (j + 1) * width) > 0)
			{
				flag = 0;
				Swap((char*)base + j * width, (char*)base + (j + 1) * width, width);
			}
		}
		if (flag)
			break;
	}


}

int cmp_int(const void* p1, const void* p2)
{
	return *(int*)p1 - *(int*)p2;
}
int main()
{
	int a[] = { 2,4,5,6,8,7,1,9,0,3 };

	bubble_sort(a, (sizeof(a) / sizeof(a[0])), sizeof(a[0]), cmp_int);

	for (int i = 0; i < 10; i++)
	{
		printf("%d ", a[i]);
	}

	return 0;
}
